package com.yida.gwj.expend.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.api.domain.GwjFinanceAccountDetail;
import com.yida.gwj.api.domain.GwjFinanceAccountMain;
import com.yida.gwj.api.domain.request.RemoteGwjFinanceAccountDetailRequest;
import com.yida.gwj.api.domain.request.RemoteGwjFinanceAccountMainRequest;
import com.yida.gwj.common.enums.GwjBusinessFlagType;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessHouse;
import com.yida.gwj.expend.domain.dto.AcceptanceReportDTO;
import com.yida.gwj.expend.domain.dto.AllocatedAmountListDTO;
import com.yida.gwj.expend.domain.dto.Application4ApprovalDTO;
import com.yida.gwj.expend.domain.dto.ApplyAppropriateReportDTO;
import com.yida.gwj.expend.domain.dto.ConfirmReceiptDTO;
import com.yida.gwj.expend.domain.dto.GwjMaintenanceFundsBusinessGetInfoDTO;
import com.yida.gwj.expend.domain.dto.GwjMaintenanceFundsBusinessListDTO;
import com.yida.gwj.expend.domain.dto.OneTimeNotificationDTO;
import com.yida.gwj.expend.domain.dto.StepConfigInfoDTO;
import com.yida.gwj.expend.domain.dto.TotalCostShareListDTO;
import com.yida.gwj.expend.domain.request.AllocatedAmountRequest;
import com.yida.gwj.expend.domain.request.BusinessProcessRequest;
import com.yida.gwj.expend.domain.request.EditFormRequest;
import com.yida.gwj.expend.domain.request.GwjMaintenanceFundsBusinessListRequest;
import com.yida.gwj.expend.domain.request.SubmitRequest;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessUrgentAppropriateService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 公维金维修资金预受理应急拨付内网业务
 *
 * @author wkz
 * @date 2023/04/10
 */
@Api(value = "公维金维修资金应急拨付预受理内网业务", tags = "公维金维修资金应急拨付预受理内网业务")
@RestController
@RequestMapping("/expend/urgent/appropriate")
public class GwjMaintenanceFundsBusinessUrgentAppropriateController extends BaseController {

    @Autowired
    private IGwjMaintenanceFundsBusinessUrgentAppropriateService maintenanceFundsBusinessUrgentAppropriateService;

    @ApiOperation(value = "查询公维金维修资金业务列表", response = GwjMaintenanceFundsBusinessListDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/list")
    public TableDataInfo list(@Validated GwjMaintenanceFundsBusinessListRequest maintenanceFundsBusinessListRequest) {
        startPage();
        List<GwjMaintenanceFundsBusinessListDTO> list = maintenanceFundsBusinessUrgentAppropriateService.getGwjMaintenanceFundsBusinessList(maintenanceFundsBusinessListRequest);
        return getDataTable(list);
    }

    @ApiOperation(value = "取件")
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @PostMapping("/take/parts")
    public AjaxResult takeParts(@RequestBody BusinessProcessRequest businessProcessRequest) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.takeParts(businessProcessRequest));
    }

    @ApiOperation(value = "基础业务信息详情", response = GwjMaintenanceFundsBusinessGetInfoDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping(value = "/{bizId}")
    public AjaxResult getInfoDetails(@PathVariable("bizId") Long bizId) {
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.getInfoDetails(bizId));
    }

    @ApiOperation(value = "分摊范围及金额-选中房屋列表", response = AllocatedAmountListDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @PostMapping("/allocated/amount/list")
    public AjaxResult allocatedAmountList(@RequestBody AllocatedAmountRequest allocatedAmountRequest) {
        startPage();
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.allocatedAmountSelect(allocatedAmountRequest));
    }

    @ApiOperation(value = "分摊范围及金额-未选中房屋列表", response = GwjMaintenanceFundsBusinessHouse.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/allocated/amount/cancel/list")
    public TableDataInfo allocatedAmountCancelList(AllocatedAmountRequest allocatedAmountRequest) {
        startPage();
        List<GwjMaintenanceFundsBusinessHouse> maintenanceFundsBusinessHouseList = maintenanceFundsBusinessUrgentAppropriateService.allocatedAmountCancelList(allocatedAmountRequest);
        return getDataTable(maintenanceFundsBusinessHouseList);
    }

    @ApiOperation(value = "预受理审核")
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @GetMapping("/pre/accept/examine")
    public AjaxResult preAcceptExamine(@RequestParam("bizId") Long bizId) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.preAcceptExamine(bizId));
    }

    @ApiOperation(value = "退件")
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @PostMapping("/pre/accept/retreat")
    public AjaxResult preAcceptRetreat(@RequestBody BusinessProcessRequest businessProcessRequest) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.preAcceptRetreat(businessProcessRequest));
    }

    @ApiOperation(value = "获取步骤按钮权限信息", response = StepConfigInfoDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping(value = "/get/step/config/info")
    public AjaxResult getStepConfigInfo() {
        return AjaxResult.success((maintenanceFundsBusinessUrgentAppropriateService.getStepConfigInfo(GwjBusinessFlagType.EXPEND_URGENT_APPROPRIATE_PRE, GwjBusinessFlagType.EXPEND_URGENT_APPROPRIATE_FORMAL)));
    }

    @ApiOperation(value = "确认受理")
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @PostMapping("/confirm/accept")
    public AjaxResult confirmAccept(@RequestBody SubmitRequest submitRequest) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.confirmAcceptance(submitRequest));
    }

    @ApiOperation(value = "提交")
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody SubmitRequest submitRequest) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.submit(submitRequest));
    }

    @ApiOperation(value = "确认收件")
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @PostMapping("/confirm/receipt")
    public AjaxResult confirmReceipt(@RequestBody ConfirmReceiptDTO confirmReceipt) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.confirmReceipt(confirmReceipt));
    }

    @ApiOperation(value = "生成财务流水")
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/generate/financial/journal")
    public AjaxResult generateFinancialJournal(@RequestParam("bizId") Long bizId) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.generateFinancialJournal(bizId));
    }

    @ApiOperation(value = "查询总账流水列表", response = GwjFinanceAccountMain.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/accountMain/list")
    public TableDataInfo accountMainList(@Validated RemoteGwjFinanceAccountMainRequest mainRequest) {
        startPage();
        return getDataTable(maintenanceFundsBusinessUrgentAppropriateService.selectGwjFinanceAccountMainList(mainRequest));
    }

    @ApiOperation(value = "查询分类账流水列表", response = GwjFinanceAccountDetail.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/accountDetail/list")
    public TableDataInfo accountDetailList(@Validated RemoteGwjFinanceAccountDetailRequest detailRequest) {
        startPage();
        return getDataTable(maintenanceFundsBusinessUrgentAppropriateService.selectGwjFinanceAccountDetailList(detailRequest));
    }

    @ApiOperation(value = "拨付申请-查询验收报告", response = AcceptanceReportDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/get/acceptance/report")
    public AjaxResult getAcceptanceReport(Long bizId) {
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.getAcceptanceReport(bizId));
    }

    @ApiOperation(value = "拨付申请-查询申请拨付报告", response = ApplyAppropriateReportDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/get/applyAppropriate/report")
    public AjaxResult getApplyAppropriateReport(Long bizId) {
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.getApplyAppropriateReport(bizId));
    }

    @ApiOperation(value = "拨付申请-查询决算费用分摊清册", response = TotalCostShareListDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/cost/list")
    public AjaxResult costList(Long bizId) {
        startPage();
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.costList(bizId));
    }

    @ApiOperation(value = "一次性通知单", response = OneTimeNotificationDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @GetMapping("/one/time/notification")
    public AjaxResult oneTimeNotification(@RequestParam("bizId") Long bizId) {
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.oneTimeNotification(bizId));
    }

    @ApiOperation(value = "获取申请报批信息", response = Application4ApprovalDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/get/application/approval")
    public AjaxResult getApplication4Approval(@RequestParam("bizId") Long bizId) {
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.getApplication4Approval(bizId));
    }

    @ApiOperation(value = "获取使用拨付申请表", response = Application4ApprovalDTO.class)
    @RequiresPermissions("gwj:expend:urgent:appropriate:list")
    @GetMapping("/get/appropriate/approval")
    public AjaxResult getAppropriate4Approve(@RequestParam("bizId") Long bizId) {
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.getAppropriate4Approval(bizId));
    }

    @ApiOperation(value = "导出房屋数据")
    @RequiresPermissions("gwj:expend:urgent:appropriate:export")
    @Log(title = "公维金维修资金业务导出房屋数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody AllocatedAmountRequest allocatedAmountRequest) {
        startPage();
        List<AllocatedAmountListDTO> list = maintenanceFundsBusinessUrgentAppropriateService.exportHouseList(allocatedAmountRequest);
        ExcelUtil<AllocatedAmountListDTO> util = new ExcelUtil<>(AllocatedAmountListDTO.class);
        util.exportExcel(response, list, "公维金维修资金业务房屋数据");
    }

    @ApiOperation(value = "回退")
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @PostMapping("/fallback")
    public AjaxResult fallback(@RequestBody SubmitRequest submitRequest) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.fallback(submitRequest));
    }

    @ApiOperation(value = "修改公维金表单信息")
    @RequiresPermissions("gwj:expend:urgent:appropriate:edit")
    @Log(title = "修改公维金表单信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit/form")
    public AjaxResult editForm(@Valid @RequestBody EditFormRequest editFormRequest) {
        return AjaxResult.success(maintenanceFundsBusinessUrgentAppropriateService.editForm(editFormRequest));
    }

    // -----------------------------------20230712 hmh 新增功能区-----------------------------------------------------------
    /**
     * 财务对账
     * 
     * @param submitRequest 提交请求
     * @return
     */
    @RequiresPermissions("gwj:expend:appropriate:edit")
    @PostMapping("/finance/check")
    public AjaxResult financeCheck(@Validated @RequestBody SubmitRequest submitRequest) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.financeCheck(submitRequest));
    }

    /**
     * 案例办结
     * 
     * @param submitRequest 提交请求
     * @return
     */
    @RequiresPermissions("gwj:expend:appropriate:edit")
    @PostMapping("/business/finish")
    public AjaxResult businessFinish(@Validated @RequestBody SubmitRequest submitRequest) {
        return toAjax(maintenanceFundsBusinessUrgentAppropriateService.businessFinish(submitRequest));
    }

    // -----------------------------------20230712 hmh end-----------------------------------------------------------

}
